// index.js
import { get, post } from '../../utils/request'
import { APIS } from '../../utils/api'
import {timestampToTime, getHSTime} from '../../utils/util'
// 获取应用实例
const app = getApp()

Page({
  data: {
    currentIndex: 0,
    tabs: ['我的订单', '进行中', '待付款', '已完成'],
    // 1 进行中 2 待付款 3 已完成
    orderList: [],
    statusText: ['进行中', '等待付款', '已完成'],
    btnText: ['预计金额', '去付款', '已付款']
  },
  onLoad() {
    this.getOrderList();
  },
  onShow() {

  },
  getOrderList(status = 0) {
    post(APIS.order, {status}).then(res => {
      console.log(res);
      this.setData({
        orderList: res.data.map(x => {
          return {
            ...x,
            start: timestampToTime(x.start, 1),
            end: timestampToTime(x.end, 1),
            total: getHSTime(x.end - x.start)
          }
        })
      });
    })
  },
  handleChange(e) {
    const {
      index
    } = e.target.dataset;
    this.setData({
      currentIndex: index,
    });
    this.getOrderList(index)
  },
  onShareAppMessage() {
    return getApp().globalData.shareMessage
  }
})
